package com.springboot.es.controller;

import com.springboot.es.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author sunxiaotao
 * @version 1.0
 * @date 2021-02-18 3:32 下午
 */
@RestController
@RequestMapping("/users")
public class UserController {

    @Resource
    UserService userService;

    @GetMapping("/add")
    public String createIndex() {
        try {
            userService.createIndex("user");
            return "Success";
        } catch (Exception e) {
            e.printStackTrace();
            return "Failure";
        }
    }

    @GetMapping("/ifIndex")
    public String hasIndex(String index) {
        try {
            boolean hasIndex = userService.existIndex(index);
            return String.valueOf(hasIndex);
        } catch (Exception e) {
            e.printStackTrace();
            return "Failure";
        }
    }
}
